/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaNovoFornecedor.java
 *
 * Created on 09/11/2011, 23:28:41
 */
package gui.pessoa;

import banco.pessoa.BancoCliente;
import excecoes.estoque.DinheiroNegativoException;
import excecoes.pessoa.CpfCnpjExistenteException;
import excecoes.pessoa.LocalizacaoInvalidaException;
import excecoes.pessoa.CpfCnpjInvalidoException;
import excecoes.pessoa.NomeInvalidoException;
import gui.estoque.JFrameTableEstoque;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import smartMarket.pessoa.Cliente;

/**
 *
 * @author dyego
 */
public class JFrameNovoCliente extends javax.swing.JFrame {

    // Atributos
    private String acao;
    private Integer linhaSelecionada = null;

    // Construtor
    public JFrameNovoCliente() {
        this.initCliente();
        this.acao = "cadastrar";
    }

    public JFrameNovoCliente(String cpf, int linha) {
        this.initCliente(cpf);
        this.acao = "alterar";
        this.linhaSelecionada = linha;
    }

    private void initCliente() {
        initComponents();

        try {
            BancoCliente bc = new BancoCliente();
            jTextFieldCodigo.setText("" + (bc.ultimoCodigo() + 1));
        } catch (NullPointerException e) {
        } catch (SQLException e) {
        }
    }

    private void initCliente(String cpf) {
        initComponents();
        try {
            BancoCliente bc = new BancoCliente();
            Cliente cliente = bc.buscar(cpf);

            jTextFieldBairro.setText(cliente.getBairro());
            jTextFieldCidade.setText(cliente.getCidade());
            jTextFieldCodigo.setText("" + cliente.getCodigo());
            jTextFieldEmail.setText(cliente.getEmail());
            jTextFieldEndereco.setText(cliente.getRua());
            jTextFieldNome.setText(cliente.getNome());
            jTextFieldNumero.setText(cliente.getNumero());
            jComboBoxEstado.setSelectedIndex(cliente.getEstado());
            jFormattedTextFieldCelular.setText(cliente.getCelular());
            jFormattedTextFieldCpf.setText(cliente.getCPF_CNPJ());
            jFormattedTextFieldLimite.setText("" + cliente.getLimite());
            jFormattedTextFieldTelefone.setText(cliente.getTelefone());



        } catch (CpfCnpjExistenteException ex) {
            Logger.getLogger(JFrameNovoCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (LocalizacaoInvalidaException ex) {
            Logger.getLogger(JFrameNovoCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NullPointerException e) {
        } catch (SQLException e) {
        } catch (NomeInvalidoException e) {
        } catch (DinheiroNegativoException e) {
        } catch (CpfCnpjInvalidoException e) {
        }
    }

    public Cliente getTextField() throws NomeInvalidoException, CpfCnpjInvalidoException, NumberFormatException, DinheiroNegativoException, LocalizacaoInvalidaException, SQLException, NullPointerException, CpfCnpjExistenteException {
        Cliente novoCliente = new Cliente();

        novoCliente.setCodigo(Integer.parseInt(jTextFieldCodigo.getText()));
        novoCliente.setCPF_CNPJ(jFormattedTextFieldCpf.getText(), true);
        novoCliente.setNome(jTextFieldNome.getText());
        novoCliente.setCidade(jTextFieldCidade.getText());
        novoCliente.setRua(jTextFieldEndereco.getText());
        novoCliente.setBairro(jTextFieldBairro.getText());
        novoCliente.setNumero(jTextFieldNumero.getText());
        novoCliente.setTelefone(jFormattedTextFieldTelefone.getText());
        novoCliente.setCelular(jFormattedTextFieldCelular.getText());
        novoCliente.setEstado(jComboBoxEstado.getSelectedIndex());
        novoCliente.setEmail(jTextFieldEmail.getText());
        novoCliente.setLimite(Float.parseFloat(jFormattedTextFieldLimite.getText().replace(".", "").replace(",", ".")));

        return novoCliente;
    }

    // Métodos
    private void cadastrar() {

        // Inserir exception de clientes já cadastrados através do CPF ou CNPJ
        try {

            BancoCliente bc = new BancoCliente();
            Cliente novoCliente = getTextField();

            bc.novo(novoCliente);

            Object[] addTable = {novoCliente.getCodigo(),
                novoCliente.getCPF_CNPJ(),
                novoCliente.getNome()};

            JFrameTableEstoque.model.addRow(addTable);

        } catch (NomeInvalidoException nie) {
            JOptionPane.showMessageDialog(null, nie.getMessage());
        } catch (SQLException SQLe) {
            JOptionPane.showMessageDialog(null, "Erro durante a conexão com o banco de dados");
        } catch (DinheiroNegativoException dne) {
            JOptionPane.showMessageDialog(null, dne.getMessage());
        } catch (CpfCnpjInvalidoException CPFie) {
            JOptionPane.showMessageDialog(null, CPFie.getMessage());
        } catch (LocalizacaoInvalidaException lie) {
            JOptionPane.showMessageDialog(null, lie.getMessage());
        } catch (NullPointerException npe) {
        } catch (CpfCnpjExistenteException CPFee) {
            JOptionPane.showMessageDialog(null, CPFee.getMessage());
        }
        
    }

    private void alterar() {


        try {

            BancoCliente bc = new BancoCliente();
            
            Cliente novoCliente = getTextField();
            bc.alterar(novoCliente);


            Object[] addTable = {novoCliente.getCodigo(),
                novoCliente.getCPF_CNPJ(),
                novoCliente.getNome()};

            JFrameTableCadastroCliente.model.removeRow(this.linhaSelecionada);
            JFrameTableCadastroCliente.model.insertRow(this.linhaSelecionada, addTable);


        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
        } catch (NomeInvalidoException e) {
            // TODO Auto-generated catch block
        } catch (CpfCnpjInvalidoException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException SQLe) {
            // TODO
        } catch (DinheiroNegativoException e) {
            // TODO Auto-generated catch block
        } catch (LocalizacaoInvalidaException lie) {
            JOptionPane.showMessageDialog(null, lie.getMessage());
        } catch (NullPointerException npe) {
        } catch (CpfCnpjExistenteException CPFee) {
            JOptionPane.showMessageDialog(null, CPFee.getMessage());
        }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelInformacoesAdicionais = new javax.swing.JPanel();
        jLabelTelefone = new javax.swing.JLabel();
        jLabelEmail = new javax.swing.JLabel();
        jLabelCelular = new javax.swing.JLabel();
        jTextFieldEmail = new javax.swing.JTextField();
        jFormattedTextFieldTelefone = new javax.swing.JFormattedTextField();
        jFormattedTextFieldCelular = new javax.swing.JFormattedTextField();
        jFormattedTextFieldLimite = new javax.swing.JFormattedTextField();
        jLabelLimite = new javax.swing.JLabel();
        jPanelDadosFornecedor = new javax.swing.JPanel();
        jLabelCodigo = new javax.swing.JLabel();
        jLabelNome = new javax.swing.JLabel();
        jLabelCpf = new javax.swing.JLabel();
        jTextFieldCodigo = new javax.swing.JTextField();
        jFormattedTextFieldCpf = new javax.swing.JFormattedTextField();
        jTextFieldNome = new javax.swing.JTextField();
        jPanelLocalizacao = new javax.swing.JPanel();
        jLabelEstado = new javax.swing.JLabel();
        jTextFieldEndereco = new javax.swing.JTextField();
        jLabelCidade = new javax.swing.JLabel();
        jLabelEndereco = new javax.swing.JLabel();
        jTextFieldCidade = new javax.swing.JTextField();
        jLabelNumero = new javax.swing.JLabel();
        jTextFieldNumero = new javax.swing.JTextField();
        jLabelBairro = new javax.swing.JLabel();
        jTextFieldBairro = new javax.swing.JTextField();
        jComboBoxEstado = new javax.swing.JComboBox();
        jButtonCadastrar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanelInformacoesAdicionais.setBorder(javax.swing.BorderFactory.createTitledBorder("Informações adicionais"));
        jPanelInformacoesAdicionais.setToolTipText("");
        jPanelInformacoesAdicionais.setName(""); // NOI18N

        jLabelTelefone.setText("Telefone: ");

        jLabelEmail.setText("e-mail: ");

        jLabelCelular.setText("Celular: ");

        try {
            jFormattedTextFieldTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            jFormattedTextFieldCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jFormattedTextFieldLimite.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));
        jFormattedTextFieldLimite.setText("0,00");
        jFormattedTextFieldLimite.setToolTipText("");

        jLabelLimite.setText("Crédito: ");

        javax.swing.GroupLayout jPanelInformacoesAdicionaisLayout = new javax.swing.GroupLayout(jPanelInformacoesAdicionais);
        jPanelInformacoesAdicionais.setLayout(jPanelInformacoesAdicionaisLayout);
        jPanelInformacoesAdicionaisLayout.setHorizontalGroup(
            jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelTelefone)
                    .addComponent(jLabelEmail))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jFormattedTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelCelular)
                    .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jLabelLimite)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jFormattedTextFieldLimite, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        jPanelInformacoesAdicionaisLayout.setVerticalGroup(
            jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelCelular)
                            .addComponent(jFormattedTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelLimite)
                            .addComponent(jFormattedTextFieldLimite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelInformacoesAdicionaisLayout.createSequentialGroup()
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelTelefone)
                            .addComponent(jFormattedTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelInformacoesAdicionaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelEmail)
                            .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelDadosFornecedor.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do Cliente"));
        jPanelDadosFornecedor.setToolTipText("");
        jPanelDadosFornecedor.setName(""); // NOI18N

        jLabelCodigo.setText("Código: ");

        jLabelNome.setText("Nome:");

        jLabelCpf.setText("CPF: ");

        jTextFieldCodigo.setEditable(false);
        jTextFieldCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldCodigoKeyPressed(evt);
            }
        });

        try {
            jFormattedTextFieldCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout jPanelDadosFornecedorLayout = new javax.swing.GroupLayout(jPanelDadosFornecedor);
        jPanelDadosFornecedor.setLayout(jPanelDadosFornecedorLayout);
        jPanelDadosFornecedorLayout.setHorizontalGroup(
            jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDadosFornecedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelNome)
                    .addComponent(jLabelCodigo))
                .addGap(18, 18, 18)
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDadosFornecedorLayout.createSequentialGroup()
                        .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(91, 91, 91)
                        .addComponent(jLabelCpf)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jFormattedTextFieldCpf, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanelDadosFornecedorLayout.setVerticalGroup(
            jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDadosFornecedorLayout.createSequentialGroup()
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCodigo)
                    .addComponent(jFormattedTextFieldCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCpf))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDadosFornecedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNome)
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelLocalizacao.setBorder(javax.swing.BorderFactory.createTitledBorder("Localização"));

        jLabelEstado.setText("Estado: ");

        jTextFieldEndereco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldEnderecoActionPerformed(evt);
            }
        });

        jLabelCidade.setText("Cidade: ");

        jLabelEndereco.setText("Endereço: ");

        jLabelNumero.setText("Numero: ");

        jLabelBairro.setText("Bairro: ");

        jComboBoxEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Acre", "Alagoas", "Amapá", "Amazonas", "Bahia", "Ceará", "Distrito Federal", "Espírito Santo", "Goiás", "Maranhão", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Pará", "Paraíba", "Paraná", "Pernambuco", "Piauí", "Roraima", "Rondônia", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", "Santa Catarina", "São Paulo", "Sergipe", "Tocantins" }));
        jComboBoxEstado.setToolTipText("");

        javax.swing.GroupLayout jPanelLocalizacaoLayout = new javax.swing.GroupLayout(jPanelLocalizacao);
        jPanelLocalizacao.setLayout(jPanelLocalizacaoLayout);
        jPanelLocalizacaoLayout.setHorizontalGroup(
            jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLocalizacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelBairro)
                    .addComponent(jLabelCidade)
                    .addComponent(jLabelEndereco))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldBairro)
                    .addComponent(jTextFieldEndereco)
                    .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelNumero)
                    .addComponent(jLabelEstado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBoxEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(66, Short.MAX_VALUE))
        );
        jPanelLocalizacaoLayout.setVerticalGroup(
            jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLocalizacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelCidade))
                    .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBoxEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelEstado)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEndereco)
                    .addComponent(jLabelNumero)
                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanelLocalizacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelBairro)
                    .addComponent(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonCadastrar.setText("Cadastrar");
        jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCadastrarActionPerformed(evt);
            }
        });

        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonCancelarMousePressed(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonCancelarMouseClicked(evt);
            }
        });
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButtonCancelar)
                            .addGap(18, 18, 18)
                            .addComponent(jButtonCadastrar))
                        .addComponent(jPanelInformacoesAdicionais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanelLocalizacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanelDadosFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jPanelDadosFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanelLocalizacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanelInformacoesAdicionais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCadastrar)
                    .addComponent(jButtonCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jTextFieldCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCodigoKeyPressed
}//GEN-LAST:event_jTextFieldCodigoKeyPressed

private void jTextFieldEnderecoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldEnderecoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextFieldEnderecoActionPerformed

private void jButtonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCadastrarActionPerformed
    if (this.acao.equals("cadastrar")) {
        this.cadastrar();
    } else {
        this.alterar();
    }

    this.setVisible(false);
}//GEN-LAST:event_jButtonCadastrarActionPerformed

private void jButtonCancelarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCancelarMousePressed
    this.setVisible(false);
}//GEN-LAST:event_jButtonCancelarMousePressed

private void jButtonCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCancelarMouseClicked
}//GEN-LAST:event_jButtonCancelarMouseClicked

private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButtonCancelarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCadastrar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JComboBox jComboBoxEstado;
    private javax.swing.JFormattedTextField jFormattedTextFieldCelular;
    private javax.swing.JFormattedTextField jFormattedTextFieldCpf;
    private javax.swing.JFormattedTextField jFormattedTextFieldLimite;
    private javax.swing.JFormattedTextField jFormattedTextFieldTelefone;
    private javax.swing.JLabel jLabelBairro;
    private javax.swing.JLabel jLabelCelular;
    private javax.swing.JLabel jLabelCidade;
    private javax.swing.JLabel jLabelCodigo;
    private javax.swing.JLabel jLabelCpf;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JLabel jLabelEndereco;
    private javax.swing.JLabel jLabelEstado;
    private javax.swing.JLabel jLabelLimite;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelNumero;
    private javax.swing.JLabel jLabelTelefone;
    private javax.swing.JPanel jPanelDadosFornecedor;
    private javax.swing.JPanel jPanelInformacoesAdicionais;
    private javax.swing.JPanel jPanelLocalizacao;
    private javax.swing.JTextField jTextFieldBairro;
    private javax.swing.JTextField jTextFieldCidade;
    private javax.swing.JTextField jTextFieldCodigo;
    private javax.swing.JTextField jTextFieldEmail;
    private javax.swing.JTextField jTextFieldEndereco;
    private javax.swing.JTextField jTextFieldNome;
    private javax.swing.JTextField jTextFieldNumero;
    // End of variables declaration//GEN-END:variables
}
